﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="maincard_recharge.aspx.cs" Inherits="Default3" MaintainScrollPositionOnPostback="true" Title="油卡管理 - 主卡充值" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style7 {
            font-size: small;
            text-align: left;
            width: 80%;
            float: left;
            display: inline;
        }

        .style21 {
            font-size: small;
        }

        .right {
            width: 18%;
            float: right;
        }

        #newdata {
            color: rgb(51, 51, 51);
            font-size: small;
            border-collapse: collapse;
        }
    </style>
    <script language="JavaScript" type="text/javascript" src="Js/datejs/WdatePicker.js"
        defer="defer"></script>
    <script language="JavaScript" type="text/javascript" src="Js/Calendar.js"></script>
</head>
<body background="images/login-bg.jpg">
    <form id="form1" runat="server">
        <div style="text-align: center">
            <div class="style7">
                <span>当前位置：</span><asp:HyperLink ID="HyperLink1" runat="server"
                    NavigateUrl="~/index.aspx" Style="color: #000000"
                    ToolTip="点击返回主页面">主页面</asp:HyperLink>
                <span>→ 编辑</span>主卡充值<br class="style7" />
                <br />
            </div>
            <div class="right">
                <br />
            </div>
            <br />
            <div>
                <table id="table7" align="center" border="0" cellpadding="0" cellspacing="0"
                        width="95%">
                        <tr>
                            <td height="10" width="9">
                                <img align="absMiddle" border="0" height="10" src="images/l_1_1.jpg"
                                    width="9" /></td>
                            <td background="images/l_1_8.jpg" width="100%"></td>
                            <td height="10" width="9">
                                <img align="absMiddle" border="0" height="10" src="images/l_1_7.jpg"
                                    width="9" /></td>
                        </tr>
                        <tr>
                            <td background="images/l_1_2.jpg" class="style22"></td>
                            <td align="left" bgcolor="#ffffff" valign="top" width="100%" class="style22">
                                <table id="table8" align="center" border="0" cellpadding="0" cellspacing="0"
                                    width="100%">
                                    <tr>
                                        <td class="style18"><b>&nbsp; 日期范围:<asp:TextBox ID="txtTime0" runat="server" onclick="showcalendar(this)" Width="80px"/>
                                            至<asp:TextBox ID="txtTime1" runat="server" onclick="showcalendar(this)" Width="80px"/>
            &nbsp;&nbsp; 办理人:<asp:TextBox ID="txtMan" runat="server" Width="80px"/></b><br /><br />
                                            
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;
                                <asp:Label ID="Label_tiaojian" runat="server" Style="color: #FF3300"
                                    Text="Label"></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <table id="table9" border="0" cellpadding="0" cellspacing="0" width="100%">
                                                <tr>
                                                    <td background="images/line.jpg" height="1"></td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <table id="table10" border="0" cellpadding="0" cellspacing="0" width="100%">
                                                            <tr>
                                                                <td align="middle" height="35" width="24%">
                                                                    <img align="absMiddle" border="0" height="25" src="images/l_1_10.jpg"
                                                                        width="19" /></td>
                                                                <td align="left" style="text-align: center" width="54%">
                                                                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/sub_1.jpg"
                                                                        OnClick="ImageButton1_Click" />
                                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                        <asp:ImageButton ID="ImageButton2" runat="server"
                                                            ImageUrl="~/images/sub_2.jpg" OnClick="ImageButton2_Click" />
                                                                </td>
                                                                <td align="middle" valign="center" width="22%">
                                                                    <img align="absMiddle" border="0" height="15" src="images/l_1_12.jpg"
                                                                        width="49" /></td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td background="images/l_1_6.jpg" class="style22"></td>
                        </tr>
                        <tr>
                            <td height="10" width="9">
                                <img align="absMiddle" border="0" height="10" src="images/l_1_3.jpg"
                                    width="9" /></td>
                            <td background="images/l_1_4.jpg"></td>
                            <td height="10" width="9">
                                <img align="absMiddle" border="0" height="10" src="images/l_1_5.jpg"
                                    width="9" /></td>
                        </tr>
                    </table>
            </div>
            <br />
            <b>
                <br />
                主卡充值列表<br />
                <br />
                <asp:GridView ID="GridView1" runat="server" AllowPaging="True" Width="80%"
                    AutoGenerateColumns="False" CellPadding="4" DataKeyNames="id,i,amount"
                    DataSourceID="SqlDataSource1" EmptyDataText="没有充值数据"
                    EnableModelValidation="True" ForeColor="#333333" GridLines="None"
                    Style="text-align: center; font-size: small"
                    OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" PageSize="30" OnPageIndexChanging="GridView1_PageIndexChanging">
                    <AlternatingRowStyle BackColor="White" />
                    <Columns>
                        <asp:CommandField ShowDeleteButton="True" /><asp:TemplateField HeaderText="序号" ItemStyle-ForeColor="Gray"></asp:TemplateField>
                        <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" Visible="False" />
                        <asp:BoundField DataField="changetime" HeaderText="日期" ItemStyle-Width="300" SortExpression="changetime" DataFormatString="{0:yyyy-MM-dd}" />
                        <asp:BoundField DataField="amount" HeaderText="充值金额（元）" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" SortExpression="amount" DataFormatString="{0:C}" />
                        <asp:BoundField DataField="balance" HeaderText="当前余额（元）" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" SortExpression="balance" DataFormatString="{0:C}" />
                        <asp:BoundField DataField="addname" HeaderText="办理人" SortExpression="addname" ItemStyle-Width="300" />
                    </Columns>
                    <EditRowStyle BackColor="#2461BF" />
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#EFF3FB" />
                    <SelectedRowStyle BackColor="#336699" Font-Bold="True" ForeColor="#333333" />
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                    ConnectionString="<%$ ConnectionStrings:xxnewsConnectionString %>"
                    DeleteCommand="
UPDATE t SET balance = balance-@amount
FROM (select ROW_NUMBER() over (order by changetime desc,addtime desc,id desc) as i,zhuka.*
from youkaguanli_maincard_detail as zhuka) t
where i<@i;DELETE FROM youkaguanli_maincard_detail WHERE (id = @id);"
                    InsertCommand="
INSERT INTO youkaguanli_maincard_detail (changetime, amount, balance, addname, addip)
SELECT TOP (1) @changetime, @amount, balance +@amount ,@addname , @addip
FROM youkaguanli_maincard_detail
where changetime&lt;=cast(@changetime as smalldatetime) or id=1
ORDER BY changetime DESC, addtime DESC, id DESC;
UPDATE t SET balance = balance +@amount
FROM (select ROW_NUMBER() over (order by changetime desc,addtime desc,id desc) as i,zhuka.*
from youkaguanli_maincard_detail as zhuka) t
where changetime>cast(@changetime as smalldatetime);"
                    SelectCommand="select * FROM (SELECT ROW_NUMBER() over (order by changetime desc,addtime desc,id desc) as i,id, changetime, amount, balance, addname, addtime, addip FROM  youkaguanli_maincard_detail) as t WHERE amount>=0 order by i">
                    <DeleteParameters>
                        <asp:Parameter Name="id" />
                        <asp:Parameter Name="i" />
                        <asp:Parameter Name="amount" />
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:Parameter Name="changetime" Type="DateTime" />
                        <asp:Parameter Name="amount" Type="Decimal" />
                        <asp:Parameter Name="addname" />
                        <asp:Parameter Name="addip" />
                    </InsertParameters>
                </asp:SqlDataSource>
                <br />
                <table id="newdata" border="0" cellspacing="0" cellpadding="4">
                    <tbody>
                        <tr align="left">
                            <td align="right">日期<font color="red">*</font></td>
                            <td>
                                <asp:TextBox ID="txtChangeTime" runat="server" onclick="showcalendar(this)" Width="80px"/>
                                <asp:RequiredFieldValidator ID="vChangeTime" runat="server" ControlToValidate="txtChangeTime" ErrorMessage="请输入日期" SetFocusOnError="True" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr align="left">
                            <td align="right">充值金额（元）<font color="red">*</font></td>
                            <td>
                                <asp:TextBox ID="txtAmount" runat="server" Width="80px" Text="0" Style="ime-mode: disabled" onkeypress="if((event.keyCode<48 ||event.keyCode>57) &&event.keyCode!=46) {event.returnValue=false;} else {event.returnValue=true;}" />
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtAmount" ErrorMessage="请输入充值" Display="Dynamic" SetFocusOnError="True" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="txtAmount" Display="Dynamic" ErrorMessage="充值金额必须大于等于0" SetFocusOnError="True" ValidationExpression="\d+(.\d+)?" ValidationGroup="Insert"></asp:RegularExpressionValidator>
                           </td>
                        </tr>
                    </tbody>
                </table>

                <span class="style8">
                    <br />
                </span>
                <br />
                <span class="style6">
                    <asp:Button ID="Button1" runat="server" CssClass="style1"
                        OnClick="Button1_Click" Text="添加" ValidationGroup="Insert" />&nbsp;&nbsp;<asp:Button ID="Button3" runat="server" PostBackUrl="~/index.aspx" Text="返回主页面" />
                    <br />
                </span>
            </b>
            <span class="style21">&nbsp;
        &nbsp; </span>
            <span class="style21">&nbsp;&nbsp;</span><br class="style1" />
            <span class="style21">添加人：</span><asp:Label ID="Label1" runat="server"
                CssClass="style21" Text="Label"></asp:Label>
            <span class="style21">&nbsp; </span>
            <asp:Label ID="Label2" runat="server" CssClass="style21" Text="Label"></asp:Label>
            <span class="style21">&nbsp; </span>
            <asp:Label ID="Label3" runat="server" CssClass="style21" Text="Label"></asp:Label>
        </div>
    </form>
    <p class="style21" style="text-align: center">
        &nbsp;<br />
        &nbsp;安康供电段信息中心制作 2015
    </p>
</body>
</html>
